<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Item extends Controller_Base {

    public function action_list()
    {
        $category = preg_replace('/[^\w]/i', '', $this->request->param('category'));

        $sql = Model::factory('store_item')->all_sql()
            ->where('is_show', '=', 1)
            ->where('categories', 'like', "%$category%")
            ->order_by('item_id', 'desc');

        View::set_global('category', $category);

        $this->view->pagination = new Pager($sql, array('items_per_page' => 12));
    }

    public function action_detail()
    {
        $item_id = $this->request->param('id');

        if (! $item = Model::factory('store_item')->get($item_id))
        {
            $this->message('商品不存在或者已下架')
                ->render();
        }

        View::set_global('category', null);

        $this->view->set('item', $item);
    }

}
